package com.ktjy.service.impl;

import com.ktjy.dao.PetDao;
import com.ktjy.dao.impl.PetDaoOracleImpl;
import com.ktjy.entity.Pet;
import com.ktjy.service.PetService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.lang.reflect.Type;

@Service("petService")
public class PetServiceImpl implements PetService {

    @Resource(type = PetDaoOracleImpl.class)
    private PetDao petDao;


    @Override
    public boolean save(Pet pet) {
        int rows = petDao.insertPet(pet);
//        if (true) {
//            throw new RuntimeException("模拟异常");
//        }
        return rows > 0;
    }

    @Override
    public boolean update(Pet pet) {
        delay(2000);
        return false;
    }

    @Override
    public boolean delete(int id) {
        delay(2000);
        return false;
    }

    //模拟业务执行所需时间
    private void delay(int time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
